﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenHack;

namespace RetroGlider
{
    public partial class addWaypoints : Form
    {
        public addWaypoints()
        {
            InitializeComponent();
        }
        List<string> WaypointList = new List<string>();
        float last_x;
        float last_y;
        int tot_waypoints = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            timer.Enabled = true;
            tot_waypoints = 0;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer.Enabled = false;
            WalkEngine addWaypoint = new WalkEngine();
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                addWaypoint.RecordWaypoint(saveFileDialog.FileName, WaypointList);
                MessageBox.Show("Waypoint created! :-)");
                Close();
            
            }

            
        }

        private void timer_Tick(object sender, EventArgs e)
        {

            WoWEngine wowInfo = new WoWEngine();
            wowInfo.InitWoW();
            if (last_x == wowInfo.PlayerXPosition() && last_y ==  wowInfo.PlayerYPosition())
            {
                // idle
            }
            else
            {
                tot_waypoints++;
                label2.Text = tot_waypoints + " waypoints added!";
                last_x = wowInfo.PlayerXPosition();
                last_y = wowInfo.PlayerYPosition();
                WaypointList.Add("<Waypoint>" + wowInfo.PlayerYPosition() + " " + wowInfo.PlayerXPosition() + "</Waypoint>");
            }
        }
    }
}
